Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tagQuery(tags) for complex css selections and alterations #208

Merged
merged 102 commits into from
Apr 15, 2021

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Apr 1, 2021

This implementation is experimental and will probably change.


tagQuery(tags) methods

Select

  • $find(cssSelector): Find all tag elements matching the multi-element cssSelector
  • $children(cssSelector = NULL): Update the selected elements to the selected elements direct children.
  • $parent(cssSelector = NULL): Update the selected elements to the selected elements direct parents.
  • $parents(cssSelector = NULL): Update the selected elements to all ancestors of the selected elements.
  • $closest(cssSelector = NULL): Update the selected elements to closest ancestor (and including itself) of each of the selected elements.
  • $siblings(cssSelector = NULL): Get the siblings of each element in the set of matched elements.
  • $filter(fn): Update the selected elements if fn(selected_i) returns TRUE
  • $reset(): Resets the selected elements to the top level (root) tags.

Update

  • $addClass(class): Apps class(es) to each of the the selected elements.
  • $removeClass(class): Removes a set of class values from all of the selected elements.
  • $hasClass(class): Determine whether the selected elements have a given class. Returns a vector of logical values.
  • $toggleClass(class): If the a class value is missing, add it. If a class value already exists, remove it.
  • $addAttrs(...): Add named attributes to all selected children. Similar to [tagAppendAttributes()].
  • $removeAttrs(attrs): Removes the provided attributes in each of the selected elements.
  • $emptyAttrs(): Removes all attributes in each of the selected elements.
  • $hasAttr(attr): Returns a vector whose values are whether the selected element contains the non-NULL attribute.

Adjust children

  • $append(...): Add all ... objects as children after any existing children to the selected elements. Similar to [tagAppendChildren()]
  • $prepend(...): Add all ... objects as children before any existing children to the selected elements. A variation of [tagAppendChildren()]
  • $empty(): Remove all children in the selected elements. Use this method before calling $append(...) to replace all selected elements' children.

Adjust siblings

  • $after(...): Add all ... objects as siblings after each of the selected elements.
  • $before(...): Add all ... objects as siblings before each of the selected elements.
  • $replaceWith(...): Replace all selected elements with .... This also sets the selected elements to an empty set.
  • $remove(...): Remove all selected elements from the tagQuery() object. The selected elements is set to an empty set.

Generic methods

  • $each(fn): Perform function fn on each of the selected elements.

Tag Query methods

  • $asTags(selected = TRUE): Converts all tag environments to tags.
  • $root(): Return all top level (root) tags environments.
  • $selected(): Returns a list of selected tag environments.
  • $get(position): Returns the selected tag element at the position position.
  • $rebuild(): Makes sure that all tags have been upgraded to tag environments.
  • $print(): Internal print method. Called by print.htmltools.tag.query()

Current tag env design decisions

  • Tag graphs or tag environments can NOT be used in UI. These objects MUST be converted back to standard tag objects.
  • tagFunctions will not be altered in place

* Consolidate all notes to the top of the file
* Move function docs within `tag_graph()`, similar to R6 documentation. Am told all docs will be hoisted up and processed in order
* Add `$parents()` to return all ancestors
* Add `$reset()` to reset the selected els to root
* Rename `$walk(fn)` to `$each(fn)`; fn now calls `fn(els[[i]], i)`
* Remove the rage-inducing "zero width spaces". aaaaaarg!!
* Rename `$root*()` to `$graph*()`
* Move in print method to support internals
* When calling `$find("x")` if a match is found, it will spawn an additional walking of the tree
R/tag_query.R Outdated Show resolved Hide resolved
R/tag_query.R Outdated Show resolved Hide resolved
R/tag_query.R Outdated Show resolved Hide resolved
R/tag_query.R Show resolved Hide resolved
R/tag_query.R Outdated Show resolved Hide resolved
R/tag_query.R Show resolved Hide resolved
R/tag_query.R Outdated Show resolved Hide resolved
@schloerke schloerke marked this pull request as ready for review April 15, 2021 14:45
@schloerke schloerke changed the title Add tagQuery(tags) for a complex css selections and alterations Add tagQuery(tags) for complex css selections and alterations Apr 15, 2021
@schloerke schloerke merged commit 838b560 into master Apr 15, 2021
@schloerke schloerke deleted the mutate_tags branch April 15, 2021 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants